package com.sjzsqjy.asdtiang.mysql;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;

import com.sjzsqjy.asdtiang.action.AdminAction;
import com.sjzsqjy.asdtiang.util.MD5;

/**
 * Info entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "info", catalog = "hospital")
public class Info implements java.io.Serializable {

	// Fields

	private String id;
	private InfoType infoType;
	private Long version;
	private String content;
	private String title;
	private Timestamp lastUpdated;
	private Timestamp dateCreated;
	private Boolean recommand;
	private Set<InfoType> infoTypes = new HashSet<InfoType>(0);
	// Constructors
	/** default constructor */
	public Info() {
	}

	/** minimal constructor */
	public Info(Long version, String content, String title,
			Timestamp lastUpdated, Timestamp dateCreated, Boolean recommand) {
		this.version = version;
		this.content = content;
		this.title = title;
		this.lastUpdated = lastUpdated;
		this.dateCreated = dateCreated;
		this.recommand = recommand;
	}

	/** full constructor */
	public Info(InfoType infoType, Long version, String content, String title,
			Timestamp lastUpdated, Timestamp dateCreated, Boolean recommand,
			Set<InfoType> infoTypes) {
		this.infoType = infoType;
		this.version = version;
		this.content = content;
		this.title = title;
		this.lastUpdated = lastUpdated;
		this.dateCreated = dateCreated;
		this.recommand = recommand;
		this.infoTypes = infoTypes;
	}

	// Property accessors
	@GenericGenerator(name = "generator", strategy = "uuid")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "id", unique = true, nullable = false)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "info_type_id")
	public InfoType getInfoType() {
		return this.infoType;
	}

	public void setInfoType(InfoType infoType) {
		this.infoType = infoType;
	}

	@Column(name = "version", nullable = false)
	public Long getVersion() {
		return this.version;
	}

	public void setVersion(Long version) {
		this.version = version;
	}

	@Column(name = "content", nullable = false)
	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "title", nullable = false)
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "last_updated", nullable = false, length = 19)
	public Timestamp getLastUpdated() {
		return this.lastUpdated;
	}

	public void setLastUpdated(Timestamp lastUpdated) {
		this.lastUpdated = lastUpdated;
	}

	@Column(name = "date_created", nullable = false, length = 19)
	public Timestamp getDateCreated() {
		return this.dateCreated;
	}

	public void setDateCreated(Timestamp dateCreated) {
		this.dateCreated = dateCreated;
	}

	@Column(name = "recommand", nullable = false)
	public Boolean getRecommand() {
		return this.recommand;
	}

	public void setRecommand(Boolean recommand) {
		this.recommand = recommand;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "infos_1")
	public Set<InfoType> getInfoTypes() {
		return this.infoTypes;
	}

	public void setInfoTypes(Set<InfoType> infoTypes) {
		this.infoTypes = infoTypes;
	}
	public static Info validate(Info object,AdminAction adminAction){
		if(null==object.getTitle()||object.getTitle().equals("")){
			return null;
		}
		object.setVersion(1l);
		object.setDateCreated(new Timestamp((new Date()).getTime()));
		object.setLastUpdated(new Timestamp((new Date()).getTime()));
		object.setRecommand(false);
		return object;
	}

}